package com.wise.site.main;

import com.wise.site.R;
import com.wise.site.more.AboutUSActivity;
import com.wise.site.more.FeedbackActivity;
import com.wise.site.more.MorePush;
import com.wise.site.more.WeiboSettingActivity;
import com.wise.site.push.PushService;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MoreActivity extends Activity implements View.OnClickListener {
	public static final String PUSH_NEW_ACTION = "push.news.action";
	
	private BroadcastReceiver mPush = new BroadcastReceiver() {
		public void onReceive(Context context, Intent intent) {
			if(PushService.HAVINGNEW){
				findViewById(R.id.push_new).setVisibility(View.VISIBLE);
			} else {
				findViewById(R.id.push_new).setVisibility(View.GONE);
			}
		}
	};
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_more);
		((TextView)findViewById(R.id.activity_title)).setText(getString(R.string.tab_more_text));
		findViewById(R.id.title_back).setVisibility(View.GONE);
		findViewById(R.id.about_US).setOnClickListener(this);
		findViewById(R.id.weibo_setting).setOnClickListener(this);
		findViewById(R.id.feedback).setOnClickListener(this);
		findViewById(R.id.push).setOnClickListener(this);
		
		try{
			registerReceiver(mPush, new IntentFilter(PUSH_NEW_ACTION));
			if(PushService.HAVINGNEW){
				findViewById(R.id.push_new).setVisibility(View.VISIBLE);
			} else {
				findViewById(R.id.push_new).setVisibility(View.GONE);
			}
		}catch (Exception e) {
		}
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		try{
			unregisterReceiver(mPush);
		}catch (Exception e) {
		}
	}
	
	@Override
	public void onClick(View v) {
		int id = v.getId();
		Intent intent = null;
		switch(id){
		case R.id.about_US:
			intent = new Intent(this, AboutUSActivity.class);
			break;
		case R.id.weibo_setting:
			intent = new Intent(this, WeiboSettingActivity.class);
			break;
		case R.id.feedback:
			intent = new Intent(this, FeedbackActivity.class);
			break;
		case R.id.push:
			intent = new Intent(this, MorePush.class);
			PushService.HAVINGNEW = false;
			findViewById(R.id.push_new).setVisibility(View.GONE);
			break;
		}
		startActivity(intent);
	}
}
